//
//  SWHomePageTableViewController.m
//  sc-cyan-ios
//
//  Created by lvjian01 on 2017/12/14.
//  Copyright © 2017年 greenbuilding. All rights reserved.
//

#import "SWHomePageTableViewController.h"
#import <SDCycleScrollView.h>
#import "SWSearchTableViewController.h"
#import "SWHomePageCollectionTableViewCell.h"
#import "UIBarButtonItem+SWBarButtobItem.h"
#import "SWButton.h"

#import "SWMessageCenterTableViewController.h"

#import "SWProductListViewController.h"
#import "SWCompanyListViewController.h"
#import "SWInquiryListViewController.h"

#import "ZHRentMessageViewController.h"
#import "SWChooseProvienceViewController.h"
#import "ZHFindRentMsgViewController.h"
#import "ZHRentCorporateViewController.h"

//#import "SWCSView.h"


@interface SWHomePageTableViewController ()<SDCycleScrollViewDelegate>

@property (weak, nonatomic) IBOutlet SDCycleScrollView *cycleScrollView;
@property (weak, nonatomic) IBOutlet UIButton *searchButton;

@property (nonatomic, strong) SWButton *citybutton;
//@property (nonatomic, strong) UIButton *cityButton;
//@property (nonatomic, strong) UIBarButtonItem *rightBarbuttonItem;
@end

@implementation SWHomePageTableViewController

- (SWButton *)citybutton{
    
    if (!_citybutton) {
        _citybutton = [SWButton buttonWithImage:@"sy_dingwei" title:@"全国" target:self action:@selector(selectCity)];
        _citybutton.frame = CGRectMake(0, 0, 120, kTopBarHeight);

    }
    return _citybutton;
}

//- (UIButton *)cityButton{
//    if (!_cityButton) {
//        _cityButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        _cityButton.frame = CGRectMake(0, 0, 120, kTopBarHeight);
//        [_cityButton setImage:[UIImage imageNamed:@"sy_dingwei"] forState:UIControlStateNormal];
//        [_cityButton setTitle:@"全国" forState:UIControlStateNormal];
//        [_cityButton addTarget:self action:@selector(selectCity) forControlEvents:UIControlEventTouchUpInside];
//        _cityButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
//        _cityButton.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
//        _cityButton.titleEdgeInsets = UIEdgeInsetsMake(3, -25, 0, 0);
//        [_cityButton setTitleColor:UIColorFromRGB(0x808080) forState:UIControlStateNormal];
//        [_cityButton.titleLabel setFont:SYSTEMFONT(13)];
//        _cityButton.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
//    }
//    return _cityButton;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[SWHomePageCollectionTableViewCell class] forCellReuseIdentifier:NSStringFromClass([SWHomePageCollectionTableViewCell class])];
    
    
    self.cycleScrollView.layer.contents = (id)[UIImage sw_placeHolderImage].CGImage;
    self.cycleScrollView.placeholderImage = [UIImage sw_placeHolderImage];
    self.cycleScrollView.delegate = self;

    
    
    //获取数据后修改
//    self.cycleScrollView.imageURLStringsGroup = projectDetail.pictures;
    self.cycleScrollView.localizationImageNamesGroup = @[@"swcs1.jpg",@"swcs2.jpg",@"swcs3.jpg"];
    self.cycleScrollView.autoScrollTimeInterval = 2.0f;
//    self.cycleScrollView.autoScroll = (projectDetail.pictures.count > 1) ? YES : NO;
    self.cycleScrollView.autoScroll = YES;
    
    
    [self makenaviBarItems];
    
    
//    SWCSView *view = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([SWCSView class]) owner:self options:nil] lastObject];
//    [self.view addSubview:view];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:self.citybutton];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.citybutton removeFromSuperview];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)makenaviBarItems{

    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithIcon:@"sy_xiaoxi01" highIcon:@"" target:self action:@selector(showMessageView)];
}

- (void)selectCity{
    NSLog(@"显示选择城市界面");
//    self.citybutton.titleLabel.text = @"贵州黔南苗族布依族自治州";
//    self.cityButton.titleLabel.text = @"贵州黔南苗族布依族自治州";
//    [self.citybutton setTitle:@"贵州黔南苗族布依族自治州" forState:UIControlStateNormal];
    
    SWChooseProvienceViewController *proVC = [SWChooseProvienceViewController dd_instanceFromStoryboard];
    [self.navigationController showViewController:proVC sender:nil];
    
}

- (void)showMessageView{
    SWMessageCenterTableViewController *messageVC = [SWMessageCenterTableViewController dd_instanceFromStoryboard];
    
    [self.navigationController showViewController:messageVC sender:nil];
}

#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 120;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    if ((indexPath.section == 2 && indexPath.row == 0)
        ||(indexPath.section == 1 && indexPath.row == 1)
           ||(indexPath.section == 0 && indexPath.row == 0)) {
        return UITableViewAutomaticDimension;
    }
    
    
    return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 0 && indexPath.row == 0) {
        SWHomePageCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SWHomePageCollectionTableViewCell class]) forIndexPath:indexPath];

        cell.cellType = SWTableCellCollectionCellType1;
        
        cell.selectedItemWithIndex = ^(NSInteger index) {
            switch (index) {
                case 0:{
                    ZHRentMessageViewController *rentMsgVC = [[ZHRentMessageViewController alloc] init];
                 
                    [self.navigationController showViewController:rentMsgVC sender:nil];
                }
                    break;
                case 1:{//求租信息
                    ZHFindRentMsgViewController *findRentMsgVC = [[ZHFindRentMsgViewController alloc] init];
                    
                    [self.navigationController showViewController:findRentMsgVC sender:nil];
                }
                    break;
                case 2:{//租赁企业库
//                    SWCompanyListViewController *companyVC = [SWCompanyListViewController dd_instanceFromStoryboard];
//
//                    [self.navigationController showViewController:companyVC sender:nil];
                    
                    ZHRentCorporateViewController *coroprateVC = [[ZHRentCorporateViewController alloc] init];
                    
                    [self.navigationController showViewController:coroprateVC sender:nil];
                    
                }
                    break;
                    
                default:
                    break;
            }
        };
        
        return cell;
    }
    
    if (indexPath.section == 1 && indexPath.row == 1) {
        SWHomePageCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SWHomePageCollectionTableViewCell class]) forIndexPath:indexPath];

        cell.cellType = SWTableCellCollectionCellType2;
        
        cell.selectedItemWithIndex = ^(NSInteger index) {
            
        };
        return cell;
    }
    
    if (indexPath.section == 2 && indexPath.row == 0) {
        SWHomePageCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SWHomePageCollectionTableViewCell class]) forIndexPath:indexPath];

        cell.cellType = SWTableCellCollectionCellType3;
        
        cell.selectedItemWithIndex = ^(NSInteger index) {
            
        };
        
        return cell;
    }
        
    return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}





#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    
    
    
    
}

#pragma mark -- SDCycleScrollViewDelegate
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    NSLog(@"点击了图片");
    
}


@end
